﻿
function trim(s) { return (s.replace(/^(\s*|　*)/, "")).replace(/(\s*|　*)$/, ""); }

var register = {
  devid: null,
  devname: null,
  prodate: null,
  init: function() {
    var Dev = document.getElementById("txtCollectDeviceID");
    if (!Dev.disabled) {
      Dev.addEventListener("blur", reg_chkdevid);
      this.devid = false;
      this.devname = false;
      this.prodate = false;
    } else {
      this.devid = true;
      this.devname = true;
      this.prodate = true;
    }
    Dev = document.getElementById("txtCollectDeviceName");
    Dev.addEventListener("blur", reg_chkdevname);
    Dev = document.getElementById("txtProduceDate");
    Dev.addEventListener("blur", reg_chkprodate);
    Dev.addEventListener("focus", reg_focusprodate);
  },

  //检查集中器编码   2013-1-15   guoh
  chk_devid: function() {
    var Dev = $("#txtCollectDeviceID");
    var str = Dev.val();

    if (trim(str) == "") {
      Dev.next("span").addClass("error").html("<span class='ico__error'></span>" + "集中器编号为空");
      Dev.addClass("form_input_error");
      register.devid = false;
      return false;
    }
    if (str.length != 6) { //长度不正确
      Dev.next("span").addClass("error").html("<span class='ico__error'></span>" + "编码长度不正确");
      Dev.addClass("form_input_error");
      register.devid = false;
      return false;
    }

    str1 = str.substring(0, 1);
    str2 = str.substring(1, 6);
    if ((str1 >= "a" && str1 <= "z") || (str1 >= "A" && str1 <= "Z") && str2.match(/\D/) == null) {
      var rt = ajaxmethodHtml("Services/JZQ.ashx?method=CheckPrimaryKey", str);
      if (rt == "0") {
        Dev.next("span").addClass("pass").html("<span class='ico__pass'></span>");
        Dev.removeClass("form_input_error");
        register.devid = true;
        return true;
      } else {
        Dev.next("span").addClass("error").html("<span class='ico__error'></span>" + "集中器编号已存在");
        Dev.addClass("form_input_error");
        register.devid = false;
        return false;
      }
    } else {
      Dev.next("span").addClass("error").html("<span class='ico__error'></span>" + "编码格式不正确（示例：J00001）");
      register.devid = false;
      return false;
    }
  },
  //检查集中器名称   2013-1-18   guoh
  chk_devname: function() {
    var DevName = $("#txtCollectDeviceName");
    var str = DevName.val();

    if (trim(str) == "") {
      DevName.next("span").addClass("error").html("<span class='ico__error'></span>" + "集中器名称为空");
      DevName.addClass("form_input_error");
      register.devname = false;
      return false;
    } else {
      DevName.next("span").addClass("pass").html("<span class='ico__pass'></span>");
      DevName.removeClass("form_input_error");
      register.devname = true;
      return true;
    }
  },
  //检查出厂日期    2013-1-18   guoh
  chk_prodate: function() {
    var prodt = $("#txtProduceDate");
    var str = prodt.val();

    if (trim(str) == "") {
      prodt.next("span").addClass("error").html("<span class='ico__error'></span>" + "出厂日期为空");
      prodt.addClass("form_input_error");
      register.prodate = false;
      return false;
    } else {
      prodt.next("span").addClass("pass").html("<span class='ico__pass'></span>");
      prodt.removeClass("form_input_error");
      register.prodate = true;
      return true;
    }
  },
  //添加集中器信息   2013-1-18   guoh
  register_save: function() {
    if (this.devid == true &&
        this.devname == true &&
        this.prodate == true
    ) {
      // ajaxmethodHtml('Services/JZQ.ashx?method=addJZQ', "1");
      return true;
    } else {
      if (this.dev == null) {
        register.chk_devid();
      }
      if (this.devname == null) {
        register.chk_devname();
      }
      if (this.prodate == null) {
        register.chk_prodate();
      }
      return false;
    }
  },

};

//guoh
function reg_save() {
  return register.register_save();
}

function reg_chkdevid() {
  register.chk_devid();

}

function reg_chkdevname() {
  register.chk_devname();
}

function reg_chkprodate() {
  register.chk_prodate();
}

function reg_focusprodate() {
  register.chk_prodate();
}

function register_init() {
  register.init();
}

function fee_register_init() {
  register.init_fee();
}

function other_register_init() {
  register.init_other();
}

function register_step2_init() {
  register.init_2();
  document.onkeyup = function(event) {
    event = event || window.event;
    if (event.keyCode == 13) {
      register.S2_save();
    }
  };
}

function other_popup_init() {
  register.init_other_popup();
}

function password_init(params) {
  ma_pswd.init(params);
}

function set_password_init() {
  Setpwd.init();
}